import { ElMessage, ElNotification } from 'element-plus'
import { MESSAGE_TYPES } from '../constants'

/**
 * 通知管理组合式函数
 * @returns {Object} 通知方法
 */
export function useNotification() {
  
  const showMessage = (message, type = MESSAGE_TYPES.INFO, duration = 3000) => {
    ElMessage({
      message,
      type,
      duration,
      showClose: true
    })
  }

  const showNotification = (title, message, type = MESSAGE_TYPES.INFO, duration = 4500) => {
    ElNotification({
      title,
      message,
      type,
      duration,
      position: 'top-right'
    })
  }

  const success = (message, title = '成功') => {
    if (title && message) {
      showNotification(title, message, MESSAGE_TYPES.SUCCESS)
    } else {
      showMessage(message || title, MESSAGE_TYPES.SUCCESS)
    }
  }

  const error = (message, title = '错误') => {
    if (title && message) {
      showNotification(title, message, MESSAGE_TYPES.ERROR, 6000)
    } else {
      showMessage(message || title, MESSAGE_TYPES.ERROR, 5000)
    }
  }

  const warning = (message, title = '警告') => {
    if (title && message) {
      showNotification(title, message, MESSAGE_TYPES.WARNING)
    } else {
      showMessage(message || title, MESSAGE_TYPES.WARNING)
    }
  }

  const info = (message, title = '信息') => {
    if (title && message) {
      showNotification(title, message, MESSAGE_TYPES.INFO)
    } else {
      showMessage(message || title, MESSAGE_TYPES.INFO)
    }
  }

  const confirm = (message, title = '确认', options = {}) => {
    return ElMessageBox.confirm(message, title, {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: MESSAGE_TYPES.WARNING,
      ...options
    })
  }

  const prompt = (message, title = '输入', options = {}) => {
    return ElMessageBox.prompt(message, title, {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      ...options
    })
  }

  return {
    showMessage,
    showNotification,
    success,
    error,
    warning,
    info,
    confirm,
    prompt
  }
}



